<template>
  <div o-Container>
    <o-list v-bind:source="list.contract" v-bind="{ exported: output }">
      <template slot="config" slot-scope="scope">
        <div class="img_box">
          <img
            @click="showLookDiaolog(scope)"
            src="/static/skin/default/MCS/AIGC/Inventory/images/chakan.png"
            alt=""
          />
        </div>
      </template>
    </o-list>
    <SalesOrderMsg
      ref="SalesOrderMsg"
      :messageList="messageList"
      @refresh="refresh"
    ></SalesOrderMsg>
    <SalesOrderMsg_SPOMS
      ref="SalesOrderMsg_SPOMS"
      :messageList="messageList"
      @refresh="refresh"
    ></SalesOrderMsg_SPOMS>
    <AfterSaleOrderMsg
      ref="AfterSaleOrderMsg"
      :messageList="messageList"
    ></AfterSaleOrderMsg>
    <AfterSaleOrderMsg_SPOMS
      ref="AfterSaleOrderMsg_SPOMS"
      :messageList="messageList"
    ></AfterSaleOrderMsg_SPOMS>
  </div>
</template>

<script>
import SalesOrderMsg from "../Components/SalesOrderMsg.vue";
import SalesOrderMsg_SPOMS from "../Components/SalesOrderMsg_SPOMS.vue";
import AfterSaleOrderMsg from "./../Components/AfterSaleOrderMsg.vue";
import AfterSaleOrderMsg_SPOMS from "./../Components/AfterSaleOrderMsg_SPOMS.vue";
export default {
  components: {
    SalesOrderMsg,
    SalesOrderMsg_SPOMS,
    AfterSaleOrderMsg,
    AfterSaleOrderMsg_SPOMS
  },
  data() {
    return {
      octopus: this.$parent.octopus,
      list: {
        contract: {
          data: {
            id: 1216, // 菜单表的八爪鱼ID
            cellData: [
              { name: "Code",width: 360 }, // 订单编号
              { name: "NAME", width: 360 }, // 权益名称
              { name: "MerchantID", show: false }, // 买家
              { name: "PurchaserID", width: 200 }, // 买家
              { name: "PurchaseName" , show: false}, // 买家
              { name: "Quantity" }, // 购买数量
              { name: "TotalPrice" }, // 下单金额（元）
              { name: "STATUS" }, // 核销状态
              { name: "STATUSID", show: false }, // 状态
              { name: "ProductFlagList", show: false }, // 产品标签
              { name: "ProductFlagListName" }, // 产品标签
              { name: "ProductName", width: 200 }, // 产品名称
              { name: "ServiceCompanyName" }, // 服务方
              { name: "CompanyID", show: false }, // 卖家
              { name: "PurchaseCompanyName" }, // 卖家
              { name: "CreateTime", width: 160 }, // 下单时间
              { name: "ID", show: false }, // ID
              { name: "TradeTypeID", show: false }, // 交易方式
              { name: "EquityID", show: false }, // 权益ID
              { name: "PlatformID", show: false }, // 购买渠道
              { name: "SalePrice", show: false }, // 市场价格
              { name: "Remarks", show: false }, // 备注
              { name: "Mobile", show: false }, // 手机
              { name: "Contact", show: false }, // 联系人
              { name: "Integration", show: false }, // 使用积分
              { name: "CostPrice", show: false }, // 商品单价
              { name: "TypeID", show: false } // 退款订单id
            ],
            paramData: {}
          },
          configWidth: 35,
          showNumber: true
        }
      },
      repetition: true,
      messageList: {},
      messageListAdd: {},
      rightList: []
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      const data = this.list.contract.data;
      let company = this.octopus.passport.authorization.company;
      data.paramData.CompanyID = company == 1 ? "NULL" : company;
    },
    showLookDiaolog(row) {
      this.messageList = row.data.row;
      const flag = this.messageList.ProductFlagList
        ? this.messageList.ProductFlagList.split(",")
        : [];
      const bool = flag.findIndex(item => item == 27) >= 0;
      this.$nextTick(() => {
        // 判断订单状态显示不同状态的订单弹窗
        if (
          this.messageList.STATUSID != 32 &&
          this.messageList.STATUSID != 33
        ) {
          if (bool) {
            this.$refs.SalesOrderMsg_SPOMS.drawerOp();
          } else {
            this.$refs.SalesOrderMsg.drawerOp();
          }
        } else {
          if (bool) {
            this.$refs.AfterSaleOrderMsg_SPOMS.drawerOp();
          } else {
            this.$refs.AfterSaleOrderMsg.drawerOp();
          }
        }
      });
    },
    output: function(data) {
      this.octopus.tips.success("下载完成。");
    },
    search: function(cell) {},
    save: function(data) {
      // 保存
      this.octopus.tips.success(data);
      // 刷新list
      this.list.contract.control.load();
      this.back();
    },
    back: function() {
      this.panel.visible = false;
    },
    del: function(row) {
      let o = this;
      // alert("del key: " + JSON.stringify(row));
      this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.octopus.request.api.post(
            "/Octopus/Engine/Item",
            {
              id: 1188, // 菜单表的八爪鱼ID
              type: "DELETE",
              value: row.ID,
              cellData: [{ name: "ID", defaultValue: row.ID }]
            },
            // 处理回调事件，通过分析data.status.code的状态来实现。
            function(data) {
              if (data.status.code === 200) {
                o.list.contract.control.load();
              } else {
                o.octopus.tips.error(data);
              }
            }
          );
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    refresh() {
      this.list.contract.control.load();
    }
  },
  props: ["oData"]
};
</script>
<style scoped>
.el-message-box {
  background-color: #fff !important;
}

.img_box {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.img_box img {
  width: 25px;
  cursor: pointer;
}
</style>
